﻿using System;
using System.Linq;
using iss.sg4210.se18.team6s.jass.DAL;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.jass.BL
{
    public class AlertCriteriaFacade
    {
        IAlertCriteria alertCriteriaRepo = null;
        public AlertCriteriaFacade()
        {
            alertCriteriaRepo = DataAccessFactory.Instance.AlertCriteria;
        }

        public void DeleteAlertCriteria(int id)
        {
            try
            {
                alertCriteriaRepo.DeleteAlertCriteria(id);
            }
            catch (Exception ex)
            {
                throw new JASSException(JASSConstants.JASS_ERROR_DELETE, ex);
            }
        }

        public AlertCriteria GetAlertCriteria(int id)
        {
            try
            {
                return alertCriteriaRepo.GetAlertCriteria(id);
            }
            catch (Exception ex)
            {
                throw new JASSException(JASSConstants.JASS_ERROR_RETRIEVE, ex);
            }
        }

        public void UpdateAlertCriteria(DAL.AlertCriteria alertCriteria)
        {
            try
            {
                alertCriteriaRepo.UpdateAlertCriteria(alertCriteria);
            }
            catch (Exception ex)
            {
                throw new JASSException(JASSConstants.JASS_ERROR_UPDATE, ex);
            }
        }

        public void AddAlertCriteria(DAL.AlertCriteria alertCriteria)
        {
            try
            {
                alertCriteriaRepo.AddAlertCriteria(alertCriteria);
            }
            catch (Exception ex)
            {
                throw new JASSException(JASSConstants.JASS_ERROR_SAVE, ex);
            }
        }

        public IQueryable<AlertCriteria> FindAllAlertCriterias()
        {
            try
            {
                return alertCriteriaRepo.FindAllAlertCriterias();
            }
            catch (Exception ex)
            {
                throw new JASSException(JASSConstants.JASS_ERROR_RETRIEVE, ex);
            }
        }

        public IQueryable<AlertCriteria> FindAllAlertCriteriasByUser(Guid userId)
        {
            try
            {
                return alertCriteriaRepo.FindAllAlertCriteriasByUser(userId);
            }
            catch (Exception ex)
            {
                throw new JASSException(JASSConstants.JASS_ERROR_RETRIEVE, ex);
            }
        }
    }
}
